package com.example.test.dialogfactory;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.FrameLayout;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;

public class MainActivity19 extends AppCompatActivity {

    private Button mButton;
    private DialogFragment mDialogFragment;

    public static void start( Context context ) {

        Intent starter = new Intent( context, MainActivity19.class );
        context.startActivity( starter );
    }

    @Override
    protected void onCreate( Bundle savedInstanceState ) {

        super.onCreate( savedInstanceState );
        setContentView( R.layout.activity_main19 );
        initView();
        initViewAction();
    }

    private void initView() {

        mButton = (Button) findViewById( R.id.button );
    }

    private void initViewAction() {

        mDialogFragment = new DialogFragment();

        mButton.setOnClickListener( new OnClickListener() {
            @Override
            public void onClick( View v ) {

                mDialogFragment.show( getSupportFragmentManager(), "dialog" );
            }
        } );
    }

    public static class DialogFragment extends BottomSheetDialogFragment {

        private BottomSheetBehavior< FrameLayout > mBehavior;

        @NonNull
        @Override
        public Dialog onCreateDialog( @Nullable Bundle savedInstanceState ) {

            BottomSheetDialog dialog = (BottomSheetDialog) super.onCreateDialog( savedInstanceState );
            View view = getLayoutInflater().inflate( R.layout.dialog_bottom_sheet, null );
            dialog.setContentView( view );

            mBehavior = dialog.getBehavior();

            return dialog;
        }
    }
}